package com.hbq.codedemopersion.common.controller;

import com.hbq.codedemopersion.common.model.Result;
import com.hbq.codedemopersion.hbase.HbaseCreateTableDTO;
import com.hbq.codedemopersion.hbase.HbaseDataDTO;
import com.hbq.codedemopersion.hbase.HbasePutDTO;
import com.hbq.codedemopersion.hbase.IHBaseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

//@Api(tags = "文件服务")
//@RestController
//@RequestMapping("/test/hbase")
//@AllArgsConstructor
public class HbaseController {
    IHBaseService hBaseService;

    @ApiOperation("创建表")
    @PostMapping("/create")
    public Result createHbase(@RequestBody HbaseCreateTableDTO hbaseCreateTableDto) throws IOException {
        hBaseService.createTable(hbaseCreateTableDto);
        return Result.succeed("添加成功");
    }

    @ApiOperation("插入数据")
    @PostMapping("/put")
    public Result putHbase(@RequestBody HbasePutDTO hbasePutDto) throws IOException {
        hBaseService.putData(hbasePutDto);
        return Result.succeed("添加成功");
    }

    @ApiOperation("获取数据")
    @GetMapping("/get")
    public Result testHbase(@RequestBody HbaseDataDTO hbaseDataDTO) {
        //List<Map<String, String>> maps = hBaseService.queryByRowKeyPrefix("hbq_test", "0001", "cf1");
        Map<String, Map<String, String>> result = hBaseService.queryByRowKey(hbaseDataDTO);
        //Map<String, Map<String, String>> stringMapMap = hBaseService.queryByRowKey("policy", Map.of("3427751931714956b2d5db29b8171722", Set.of("vin", "family")), "cf");
        return Result.succeed(result);
    }

    @ApiOperation("获取数据2")
    @GetMapping("/get2")
    public Result testHbase2(String tableName, String rowKey, String family) {
        List<String> result = hBaseService.queryByRowKey(tableName, rowKey, family);
        return Result.succeed(result);
    }

    @ApiOperation("删除表格")
    @PostMapping("/removeTable")
    public Result removeTable(String tableName) throws IOException {
        hBaseService.removeTable(tableName);
        return Result.succeed("删除成功");
    }

    @ApiOperation("删除表数据")
    @PostMapping("/deleteData")
    public Result deleteData(@RequestBody HbaseDataDTO hbaseDataDTO) throws IOException {
        hBaseService.deleteData(hbaseDataDTO);
        //hBaseService.deleteData("hbq_test", Map.of("0001", List.of("name", "address")), "cf1");
        return Result.succeed("删除成功");
    }
}
